package com.jxsm.controller;

import com.jxsm.dao.SqlTypeDao;
import com.jxsm.pojo.ExtCProduct;
import com.jxsm.pojo.Factory;
import com.jxsm.pojo.SqlType;
import com.jxsm.service.ExtCProductService;
import com.jxsm.service.FactoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by Administrator on 2016/11/4.
 */
@Controller
public class ExtCProductController {
    @Autowired
    private ExtCProductService extCProductService;
    @Autowired
    private FactoryService factoryService ;
    @RequestMapping("/cargo/contract/tocreateExt.action")
    public String tocreatExt (String contractProductId,Map<String,Object>map){
        //获取启动状态的生成厂家
        List<Factory> factoryList=factoryService.list();
        map.put("factoryList",factoryList);
        //获取type对象；
        List<SqlType> list=extCProductService.list(null);
        map.put("type",list);
        map.put("contractProductId",contractProductId);

        //获取货物下的所有附件
        Map map1=new HashMap();
        map1.put("contractProductId",contractProductId);
        List<ExtCProduct> extCProducts=extCProductService.find(map1);
        map.put("extCProducts",extCProducts);
        return "/cargo/contracrProduct/extcproductCreate.jsp";
    }
    @RequestMapping("/cargo/contract/tocreateExtCp.action")
    public String createExtproduct(String contractProductId ,ExtCProduct extcproduct,Map<String,Object>map){
        map.put("contractProductId",contractProductId);
        extCProductService.insert(extcproduct);
    return   "redirect:/cargo/contract/tocreateExt.action";
    }
    @RequestMapping("/cargo/contract/toupdateExtProduct.action")
    public String toupdateExt(String id ,Map<String,Object>map){
        //获取启动状态的生成厂家
        List<Factory> factoryList=factoryService.list();
        map.put("factoryList",factoryList);

        //获取type对象；
        List<SqlType> list=extCProductService.list(null);
        map.put("type",list);
        System.out.println(id);
        //获取对象用于回显
        ExtCProduct extCProduct= extCProductService.get(id);
        map.put("extCProduct",extCProduct);
        return "/cargo/contracrProduct/extcproductUpdate.jsp";
    }
    @RequestMapping("/cargo/contract/toupdateExtCp.action")
    public String updaeteExtProduct(ExtCProduct extCProduct){
        extCProductService.update(extCProduct);
        return   "redirect:/cargo/contract/tocreateExt.action";
    }
}
